package org.top10.parser;

import java.util.ArrayList;
import java.util.List;

import org.top10.entity.SinaJsonData;
import org.top10.entity.Video;
import org.top10.executor.ParseSource;
import org.top10.util.TOP10Global;
import org.w3c.dom.Node;

public abstract class SinaVideoPaser extends TOPParserImpl {

	public SinaVideoPaser(String c, int t, String u) {
		super(c, t, u);
	}

	public abstract List parse(ParseSource doc) throws Exception;

	public abstract Video build(Node node, int rank) throws Exception;

	protected List<Video> sinaBuild(ParseSource doc){
		int i=doc.getTextSource().indexOf("\"data\":");
		System.out.println(doc.getTextSource().substring(i+7));
		if(i>0){
			List<SinaJsonData>SinaDatas=turnJson2List(doc.getTextSource().substring(i+7),SinaJsonData.class);
			List<Video> list = new ArrayList<Video>();
			int rank=1;
			for(SinaJsonData d:SinaDatas){
				Video v = new Video();
				v.setPlayUrl(d.getUrl());
				v.setName(d.getTitle());
				v.setRank(rank++);
				v.setPoint(d.getTop_num());
				//System.out.println(d.getTop_num());
				System.out.println(v.toString());
				list.add(v);
			}
			return list;
		}
		return null;
	}
}

class SinaDayTopParser extends SinaVideoPaser{
	public SinaDayTopParser(String c,  String u) {
		super(c,TOP10Global.TYPE_Television, u);
	}

	public Video build(Node node, int rank) throws Exception {
		return null;
	}

	public List parse(ParseSource doc) throws Exception {
		return sinaBuild(doc);
	}
}
class SinaWeekTopParser extends SinaVideoPaser{
	public SinaWeekTopParser(String c,  String u) {
		super(c,TOP10Global.TYPE_Television, u);
	}

	public Video build(Node node, int rank) throws Exception {
		return null;
	}

	public List parse(ParseSource doc) throws Exception {
		return sinaBuild(doc);
	}
}
class SinaClassTopParser extends SinaVideoPaser{
	public SinaClassTopParser(String c,  String u) {
		super(c,TOP10Global.TYPE_Television, u);
	}

	public Video build(Node node, int rank) throws Exception {
		return null;
	}

	public List parse(ParseSource doc) throws Exception {
		return sinaBuild(doc);
	}
}
class SinaMouthTopParser extends SinaVideoPaser{
	public SinaMouthTopParser(String c,  String u) {
		super(c,TOP10Global.TYPE_Television, u);
	}

	public Video build(Node node, int rank) throws Exception {
		return null;
	}

	public List parse(ParseSource doc) throws Exception {
		return sinaBuild(doc);
	}
}